草庐IT

JSON 对象

全部标签

javascript - Angularjs $http.get 将 JSON 数据作为带有转义引号而不是 json 的字符串返回

这里有一个有趣的问题。我有返回JSON的Restful后端。当我通过浏览器访问api时,它会返回一个经过验证的带有json对象的json数组。[{"GUID_Auth":null,"Email_Address":"abc@aol,"Measure_Id":1,"Title":"Prop41"}]但是当我通过angularjs发出$http.get请求时,我取回了一个带有转义引号的字符串gotsuccess:"[{\"GUID_Auth\":null,\"Email_Address\":\"abc@aol\",\"Measure_Id\":1,\"Title\":\"Prop41\"}]

javascript - 如何使用 sigma.js 显示来自 JSON 对象的数据

我想读取图的节点/边信息(sigma.js)来自JSON变量。虽然使用外部JSON文件非常容易作为通过JSON解析器的输入,我找不到使用JSON对象的方法直接在JavaScript代码中定义。似乎存在一种名为“读取”的方法,但我无法获得它可以工作(来源:https://github.com/jacomyal/sigma.js/wiki/Graph-API)。有人可以给我提示吗?这是我想要的:data={"nodes":[{"id":"n0","label":"Anode","x":0,"y":0,"size":3},{"id":"n1","label":"Anothernode","x

javascript - 在json中插入javascript变量值

我有一个JSON变量,看起来像这样:{"events":[{"event_id":"1","event_name":"Breakfast"},{"event_id":"1","event_name":"CallingBob"}]};我有两个变量x=2;y=jam;我想在json中推送变量,这样x是event_id,y是event_name,这样我的json看起来像-{"events":[{"event_id":"1","event_name":"Breakfast"},{"event_id":"1","event_name":"CallingBob"},{"event_id":"2",

javascript - 使用 Lodash 或 Underscore 按多列对对象进行分组

我有以下对象记录:{"notes":[{"id":1,"description":"hey","userId":2,"replyToId":null,"postId":2,"parentId":null},{"id":5,"description":"heytest","userId":3,"replyToId":null,"postId":2,"parentId":null},{"id":2,"description":"howareyou","userId":null,"replyToId":2,"postId":2,"parentId":null,"user":null}]}我想

返回对象的javascript函数返回[object Object]

我的函数的预期输出是{"name":"bob","number":1},但它返回[objectObject]。我怎样才能达到预期的输出?functionmyfunc(){return{"name":"bob","number":1};}myfunc(); 最佳答案 哈哈这似乎是一个简单的误会。您正在返回对象,但是对象的toString()方法是[objectObject]并且它被freecodecamp控制台隐式调用。Object.prototype.toString()varo={};//oisanObjecto.toString

javascript - 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性

在Angular2中使用新的http服务,我想对我的错误做更多的事情,而不仅仅是在控制台中抛出错误。不幸的是,我似乎无法从catch回调函数中访问我的对象属性。我的http服务调用:returnthis.http.get(this.apiUrl,options).map(this.extractData,this).catch(this.handleError)我的handleError回调fn:handleError(error){console.log(this)//undefined!if(error.status===401){this.router.navigate(['/l

javascript - AngularJS - $编译一个带有对象作为属性参数的指令

当我使用$compile创建和绑定(bind)一个指令时,我怎样才能同时添加一个变量作为属性?变量是一个对象。vardata={name:'Fred'};vardirCode='';varel=$compile(dirCode)($scope);$element.append(el);myDirective会期望:...scope:{record:'='},...我试过`vardirCode='';`相反。 最佳答案 这很简单,只需创建新范围并在其上设置数据属性即可。angular.module('app',[]);angular.

javascript - 在javascript中设置对象数组的顺序

我需要找到一种最简单的方法来设置对象数组的顺序。比如有一个数组:vararray=[{id:1,name:"Matt"},{id:2,name:"Jack"},{id:3,name:"Morgan"},{id:4,name:"Bruce"}];我已经提供了varorder=[1,4,2,3];它指的是数组项的对象id属性。现在我需要重新排序数组,所以它应该是这样的:vararray=[{id:1,name:"Matt"},{id:4,name:"Bruce"},{id:2,name:"Jack"},{id:3,name:"Morgan"}] 最佳答案

javascript - react `context` 始终为空对象

我正在尝试在我的React应用程序中设置上下文,但不知何故我无法从child访问context。这是父类:importReactfrom'react'importMenuBarfrom'./MenuBar.js'exportdefaultclassAppextendsReact.Component{staticchildContextTypes={prop:React.PropTypes.bool};getChildContext(){return{prop:true}}render(){return()}}这是我的child类(class):importReact,{Componen

javascript - 使用索引遍历 JavaScript 对象

我正在尝试循环ES6中的JavaScript对象。for(let[value,index]ofobject){dosomethingwithrestif(index>=1){//dosomethingwithfirstitem}}它工作正常,尽管当我尝试使用索引获取第一项时它在控制台中返回错误:UncaughtTypeError:Invalidattempttodestructurenon-iterableinstance关于如何使用索引遍历对象有什么想法吗?谢谢 最佳答案 这只是对jonasw解决方案的补充。如果需要当前值的key